package sair.recorder.windows;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPasswordField;
import javax.swing.JTextField;

class Listeners {

	public static class mainWinExit implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			MainWindow.mainWindow.setVisible(false);
			LoginWindow.loginWindow.setVisible(true);
		}

	}

	static class infoWindowExit implements ActionListener {
		private InfomationWindow window;

		infoWindowExit(InfomationWindow window) {
			this.window = window;
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			if (window != null) {
				window.setVisible(false);
			}
		}

	}

	static class loginButtonAncestorListener implements ActionListener {
		private JTextField username;
		private JPasswordField password;

		loginButtonAncestorListener(JTextField username, JPasswordField password) {
			this.username = username;
			this.password = password;
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			String name = username.getText();
			int pwhash = new String(password.getPassword()).hashCode();
			MainWindow.mainWindow.loginin(name, pwhash);
		}
	}

	static class exitButtonAncestorListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	}

}
